package com.itheima.reggie_auto.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie_auto.common.R;
import com.itheima.reggie_auto.dto.OrdersDto;
import com.itheima.reggie_auto.entity.Orders;
import com.itheima.reggie_auto.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 刘少宽
 * @since 2022-09-23
 */
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        ordersService.submit(orders);

        return R.success("支付成功");
    }

    @GetMapping("/userPage")
    public R<Page<OrdersDto>> userPage(int page, int pageSize){

        Page<OrdersDto> pageInfo = ordersService.page(page,pageSize);
        return R.success(pageInfo);
    }

    @PostMapping("/again")
    public R<String> again(@RequestBody Orders orders){

        ordersService.again(orders);
        return R.success("再来一单，Ok");
    }

    @GetMapping("/page")
    public R<Page<Orders>> page(int page,int pageSize,Long number,String beginTime,String endTime){
        Page<Orders> pageInfo =  ordersService.pageInfo(page,pageSize,number,beginTime,endTime);

        return R.success(pageInfo);
    }

    @PutMapping
    public R<String> updateStatus(@RequestBody Orders orders){
        ordersService.update(orders);
        return R.success("修改状态成功");
    }

}

